package com.woniuxy.servicelayer.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.dal.entity.Collect;
import com.woniuxy.dal.mapper.CollectMapper;
import com.woniuxy.dal.mapper.RangeMapper;
import com.woniuxy.dal.mapper.UserinfoMapper;
import com.woniuxy.servicelayer.CollectService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
* @author rjq51
* @description 针对表【collect(收藏表)】的数据库操作Service实现
* @createDate 2023-03-27 17:14:20
*/
@Service
public class CollectServiceImpl extends ServiceImpl<CollectMapper, Collect>
    implements CollectService {

    @Resource
    CollectMapper collectMapper;
    @Resource
    UserinfoMapper userinfoMapper;
    @Resource
    RangeMapper rangeMapper;

    // 查询收藏
    @Override
    public Page<Collect> pageSearch(Integer currentPage, Integer pageSize, Integer userId) {

        Page<Collect> page = new Page<>(currentPage, pageSize);
        QueryWrapper<Collect> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("userId", userId);
        Page<Collect> collectionPage = collectMapper.selectPage(page, queryWrapper);
        return collectionPage;

    }


    //删除收藏
    @Override
    public void deleteById(Integer collectionId) {
        collectMapper.deleteById(collectionId);
    }

//    @Override
//    public void addCollection(Collect collect) {
//        collectMapper.insert(collect);
//    }

    @Override
    public void addFavorite(Collect collect) {
        collectMapper.insert(collect);
    }


    @Override
    public void cancelFavorite(Integer rangeId, Object userId) {
        QueryWrapper<Collect> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("rangeId",rangeId);
        queryWrapper.eq("userId",userId);
        collectMapper.delete(queryWrapper);
    }




}




